package com.anpy.bill.controller;

import com.anpy.bill.model.vo.LoginRequestVO;
import com.anpy.bill.service.UserService;
import com.anpy.common.service.model.result.ApiResult;
import com.personal.dao.entity.UserEntity;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@MapperScan(value = "com.anpy.user.mapper")
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/login")
    public ApiResult<UserEntity> login(@RequestBody LoginRequestVO loginRequestVO){
        return ApiResult.success(userService.login(loginRequestVO));
    }

    @PostMapping("/save")
    public ApiResult<Boolean> saveUserInfo(@RequestBody UserEntity userEntity){
        return ApiResult.success(userService.saveUserInfo(userEntity));
    }

    @PostMapping("/update")
    public ApiResult<Boolean> uploadUserInfo(@RequestBody UserEntity userEntity){
        return ApiResult.success(userService.uploadUserInfo(userEntity));
    }

    @GetMapping("/load")
    public ApiResult<UserEntity> loadUserInfo(Integer userId){
        return ApiResult.success(userService.loadUserInfo(userId));
    }
    @GetMapping("/cache")
    public ApiResult<UserEntity> cache(String phone){
        return ApiResult.success(userService.loadCacheData(phone));
    }

    @GetMapping("/test")
    public ApiResult<UserEntity> test(){
        return ApiResult.success();
    }
}
